SetDetailPanel = function() {
	var this_panel = this;
	
	this.listeners = {
		show : function(){
			this_panel.getBottomToolbar().init();
			editItemWindow.reloadComboBox();
		}
	};
	
	var remove = function(){
		Ext.MessageBox.confirm("确认","确认删除该项目?",function(btn){
			if(btn == "yes"){
				var recs = this_panel.selModel.getSelections();
				var array = new Array();
				Ext.each(recs,function(rec,i){
					array.push(rec.get("id"));
				});
				var ids = array.join(",");
				Ajax({
					url : "item/delete.action",
					params : {ids : ids},
					maskTarget : this_panel,
					success : function(){
						setDetailPanel.getTopToolbar().init();
					}
				});
			}
		});
	};
	
	var sm = new Ext.grid.CheckboxSelectionModel({
		listeners : {
			selectionchange : function(){
				var num = this_panel.getSelectionModel().getSelections().length;
				this_panel.getTopToolbar().deleteButton.setDisabled(num==0);
				this_panel.getTopToolbar().editButton.setDisabled(num!=1);
				this_panel.getTopToolbar().updateBack.setDisabled(num!=1);
			}
		}
	});
	var store =  new Ext.data.GroupingStore({
		reader : itemReader,
		groupField:'person.name'
	});
	
	SetDetailPanel.superclass.constructor.call(this, {
		title : "销售项目管理",
		sm: sm,
		loadMask : true,
		enableHdMenu : false,
		autoExpandColumn : "hospital",
		view: new Ext.grid.GroupingView({
			hideGroupedColumn : true,
			startCollapsed : true,
            groupTextTpl: '{text} ({[values.rs.length]}个项目)'
	    }),
	    bbar : new SeasonToolbar({
			panel : this_panel,
			url : "item/findAllBySeason.action",
			type : "sell"
		}),
		tbar : [
		   {text : "添加项目",ref : "addButton",iconCls : "add",handler : function(){addItemWindow.show();}},
		   {text : "删除项目",ref : "deleteButton",iconCls : "delete",handler: remove},
		   {text : "修改销售信息",ref : "editButton",disabled : true,iconCls : "edit",handler : function(){
				var rec = this_panel.getSelectionModel().getSelected();
				editItemWindow.setData(object2Entity(rec.data,"item"));
				editItemWindow.show();
			}},
		   {text : "更新回款信息",ref : "updateBack",disabled : true,iconCls : "edit",handler : function(){
				var rec = this_panel.getSelectionModel().getSelected();
				updateBackInfoWindow.setData(object2Entity(rec.data,"item"));
				updateBackInfoWindow.show();
			}}],
		colModel: new Ext.grid.ColumnModel({
			defaults : {
				align : "center",
				width : 90
			},
			columns : [sm,{hidden : true,dataIndex : "id"},
	   		{header : "医院名称",dataIndex : "hospital.name",align : "left",id : "hospital"}, 
	   		{header : "货品名称",dataIndex : "product.name",align : "left",width : 120},
	   		{header : "销售人员",dataIndex : "person.name"},
	   		{header : "发货日期",dataIndex : "sellDate"},
	   		{header : "回款日期",dataIndex : "backDate",renderer : backDateRender},
	   		{header : "超期(日)",dataIndex : "outDay",renderer : outDayRender},
	   		{header : "单位",dataIndex : "unit.name"}, 
	   		{header : "数量",dataIndex : "count"}, 
	   		{header : "售价",dataIndex : "sellPrice"}, 
	   		{header : "销售金额",dataIndex : "sellSum"},
	   		{header : "进价",dataIndex : "buyPrice"}]
		 }),
		store : store
	});
};
Ext.extend(SetDetailPanel, Ext.grid.GridPanel);
var setDetailPanel = new SetDetailPanel();